import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, 项目将不会显示在侧边栏中(default is false)
 * alwaysShow: true               if set true, 将始终显示根菜单
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, 不会缓存该页(default is false)
    affix: true                  if set true, 标签将粘贴在标签视图中
    breadcrumb: false            if set false,该项目将隐藏在面包屑(default is true)
    activeMenu: '/example/list'  if set path, 侧边栏将突出显示您设置的路径
  }
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/home/index'),
        name: 'home',
        meta: { title: '首页', icon: 'user', affix: true }
      }
    ]
  },
  {
    path: '/briefIntroduction',
    component: Layout,
    redirect: '/briefIntroduction/index',
    meta: { title: '项目简介', icon: 'user'},
    children: [
      {
        path: 'index',
        component: () => import('@/views/briefIntroduction/index'),
        name: 'briefIntroduction',
        meta: { title: '项目简介1'}
      },
      {
        path: 'aaindex2',
        component: () => import('@/views/briefIntroduction/index'),
        name: 'briefIntroduction2',
        meta: { title: '项目简介2'}
      }
    ]
  }, {
    path: '/goods',
    component: Layout,
    redirect: '/goods/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/goods/index'),
        name: 'goods',
        meta: { title: '商品管理', icon: 'user'}
      }
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: '/member/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/member/index'),
        name: 'member',
        meta: { title: '数据中心', icon: 'user'}
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    redirect: '/news/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/news/index'),
        name: 'news',
        meta: { title: '咨询', icon: 'user'}
      }
    ]
  },
  // {
  //   path: '/news-detail',
  //   component: Layout,
  //   redirect: '/news-detail/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/news-detail/index'),
  //       name: 'news-detail',
  //       meta: { title: '咨询详情', icon: 'user'}
  //     }
  //   ]
  // },
  // {
  //   path: '/order',
  //   component: Layout,
  //   redirect: '/order/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/order/index'),
  //       name: 'order',
  //       meta: { title: '订单管理', icon: 'user'}
  //     }
  //   ]
  // },
  // {
  //   path: '/pics',
  //   component: Layout,
  //   redirect: '/pics/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/pics/index'),
  //       name: 'pics',
  //       meta: { title: 'pics', icon: 'user'}
  //     }
  //   ]
  // },
]
export const asyncRoutes = [
  {
    path: '/news-detail',
    component: 'Layout',
    redirect: '/news-detail/index',
    children: [
      {
        path: 'index',
        component: 'news-detail',
        name: 'news-detail',
        meta: { title: '咨询详情', icon: 'user'}
      }
    ]
  },
  // {
  //   path: 'order',
  //   component: 'Layout',
  //   name:'derr',
  //   redirect: '/order/index',
  //   meta: { title: "基础模块", icon: "tab" },
  //   children: [
  //     {
  //       path: '/index',
  //       component: 'order/index.vue',
  //       name: 'order',
  //       meta: {
  //         title: '订单管理',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },
  {
    // path: 'pics',
    // component: 'Layout',
    // name:'deeeerr',
    // meta: { title: "基础ee模块", icon: "tab" },
    
    path: '/pics',
    component: 'Layout',
    // redirect: '/pics/index',
    // path: '/pics',
    // component: 'Layout',
    // redirect: '/pics/index',
    children: [
      {
        path: '/index1',
        component: 'pics/index.vue',
        name: 'pics',
        meta: {
          title: 'pics',
          icon: 'user',
          roles: ['admin', 'editor']
        }
      }
    ]
  },
]
const createRouter = () => new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: constantRoutes
})
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

//获取原型对象上的push函数
export default router
